package com.leetcode.partition3;

import com.leetcode.common.ListNode;

/**
 * @author `RKC`
 * @date 2021/8/11 10:44
 */
public class LC206反转链表 {

    public static ListNode reverseList(ListNode head) {
        return recursion(head);
    }

    private static ListNode doubleIndex(ListNode head) {
        ListNode next, cur = head, prev = null;
        while (cur != null) {
            next = cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }
        return prev;
    }

    private static ListNode recursion(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        //p指针指向了反转后的那部分的头指针
        ListNode p = recursion(head.next);
        head.next.next = head;
        head.next = null;
        return p;
    }
}
